package com.menghao.sso.server.model.validation;

import com.menghao.sso.server.model.Principal;
import lombok.Getter;

import java.io.Serializable;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 表示成功的身份验证请求。 它包含验证请求的主体以及额外的元信息，例如验证日期和属性映射。
 */
public class Authentication implements Serializable {

    /**
     * 获取委托人
     */
    @Getter
    private final Principal principal;
    /**
     * 认证发生的日期/时间
     */
    @Getter
    private final Date authenticatedDate;
    /**
     * 额外信息
     */
    @Getter
    private final Map attributes;

    public Authentication(final Principal principal) {
        this(principal, null);
    }

    public Authentication(final Principal principal, final Map attributes) {

        if (principal == null) {
            throw new IllegalArgumentException("principal cannot be null on "
                    + this.getClass().getName());
        }
        this.principal = principal;
        this.attributes = Collections.unmodifiableMap(attributes == null
                ? new HashMap() : attributes);
        this.authenticatedDate = new Date();
    }
}
